import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'


const modules = import.meta.glob('../views/**/*.vue')

// 动态生成路由
const routes = Object.keys(modules).map((key) => {
  const path = key
    .replace('../views', '') // 去除 views 根路径
    .replace('.vue', '') // 去除文件扩展名
    .replace(/\/index$/, '') // 如果文件名是 index.vue，去掉目录层级
    .toLowerCase() // 将路径转为小写，避免路由大小写问题

  return {
    path: path === '/home' ? '/' : path, // 处理首页的特殊情况
    component: modules[key],
  }
})
console.log(routes, "lkshfdksj")
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [

  ]
})

export default router
